import moment from "moment"
// 公共 方法

export const deepCopy = (obj: any, hash = new WeakMap()) => {
  if (obj instanceof RegExp) return new RegExp(obj);

  if (obj instanceof Date) return new Date(obj);

  if (obj === null || typeof obj !== "object") {
    return obj;
  }

  if (hash.has(obj)) {
    return hash.get(obj);
  }

  const t = obj.constructor();

  hash.set(obj, t);

  for (let key in obj) {
    // eslint-disable-next-line no-prototype-builtins
    if (obj.hasOwnProperty(key)) {
      t[key] = deepCopy(obj[key], hash);
    }
  }
  return t;
}


// 格式化时间
export const formatTime = (time: any, format = "YYYY-MM-DD HH:mm:ss") => {
  if (!time) return "-";
  return moment(time).format(format);
}